import { BasicPageSearchParams } from "/@/api/model/baseModel";
import { defHttp } from '/@/utils/http/axios';


// 项目管理->采样计划->采样计划明细
enum Api {
  list = '/CheckPlanDetail/list',
  view = '/CheckPlanDetail/view/',
  add = '/CheckPlanDetail/add',
  update = '/CheckPlanDetail/update',
  del = '/CheckPlanDetail/del/',

  getDetailList = '/CheckPlanDetail/getDetailList/',

  getCheckItemListByType = '/CheckItem/getAll', 
  getCheckItemList = '/CheckItem/list', // 获取所有检测项目列表
  getCheckSpotList = '/CheckSpot/list', // 获取采样点列表
}


export const list = (params?: any) => {
  const query = params && { pageNum: params.pageNum, pageSize: params.pageSize };
  let entity = params || {};
  if (entity) {
    delete entity['pageNum'];
    delete entity['pageSize'];
  }
  const queryParam = { query, entity } as BasicPageSearchParams<any>;
  return defHttp.post<any>({ url: Api.list, params: queryParam });
};

export const view = (id?: number) => {
  return defHttp.get<any>({ url: Api.view + id });
};

export const add = (params) =>
  defHttp.post<any>({ url: Api.add, params });

export const update = (params) =>
  defHttp.post<any>({ url: Api.update, params });

export const del = (id?: number) =>
  defHttp.post<any>({ url: Api.del + id });

export const getDetailList = (params?: any) => {
  console.log('getDetailList params:', params);
  return defHttp.get<any>({ url: Api.getDetailList + params.planId });
};

export const getCheckSpotList = (params?: any) => {
  const query = params && { pageNum: params.pageNum, pageSize: params.pageSize };
  let entity = params || {};
  if (entity) {
    delete entity['pageNum'];
    delete entity['pageSize'];
  }
  const queryParam = { query, entity } as BasicPageSearchParams<any>;
  return defHttp.post<any>({ url: Api.getCheckSpotList, params: queryParam });
};

export const getCheckItemListByType = (type: string) =>{
  return defHttp.get<any>({ url: Api.getCheckItemListByType + '?type=' + type });
}

export const getCheckItemList = (params?: any) => {
  const query = params && { pageNum: params.pageNum, pageSize: params.pageSize };
  let entity = params || {};
  if (entity) {
    delete entity['pageNum'];
    delete entity['pageSize'];
  }
  const queryParam = { query, entity } as BasicPageSearchParams<any>;
  return defHttp.post<any>({ url: Api.getCheckItemList, params: queryParam });
};